
package com.trydofor.a9task.base.user.help;

import com.trydofor.a9task.base.code.sysd.Language;
import com.trydofor.a9task.base.code.sysd.UserGender;
import com.trydofor.a9task.base.code.sysd.UserStatus;
import com.trydofor.a9task.base.user.bean.UserMain;
import com.trydofor.a9task.base.user.bean.UserMainRw;
import com.trydofor.aloe.exception.Exceptions;

/**
 * @author : Shi Rongjiu (www.trydofor.com)
 * @date : Dec 11, 2012
 * @see :
 */

public class UserMainBuilder {
    
    public static UserMainBuilder user(int id, String name) {
        return new UserMainBuilder(id, name);
    }
    
    private final UserMainRw  user;
    private transient boolean isDone = false;
    
    private UserMainBuilder(int id, String name) {
        user = new UserMainRw();
        user.setId(id);
        user.setName(name);
        
        user.setGender(UserGender.$UNKNOWN);
        user.setLanguage(Language.$EN_US);
        user.setStatus(UserStatus.$INACTIVE_STATUS);
        user.setTimeDiff(0);
        user.setMainMail("trydofor@gmail.com");
    }
    
    public UserMainBuilder gender(int gender) {
        Exceptions.checkIllegalState(isDone, "can not set when it's done");
        user.setGender(gender);
        return this;
    }
    
    public UserMainBuilder language(int lang) {
        Exceptions.checkIllegalState(isDone, "can not set when it's done");
        user.setLanguage(lang);
        return this;
    }
    
    public UserMainBuilder status(int status) {
        Exceptions.checkIllegalState(isDone, "can not set when it's done");
        user.setStatus(status);
        return this;
    }
    
    public UserMainBuilder timeDiff(int diff) {
        Exceptions.checkIllegalState(isDone, "can not set when it's done");
        user.setTimeDiff(diff);
        return this;
    }
    
    public UserMainBuilder mainMail(String mail) {
        Exceptions.checkIllegalState(isDone, "can not set when it's done");
        user.setMainMail(mail);
        return this;
    }
    
    public UserMain done() {
        isDone = true;
        return user;
    }
}
